package com.adminsystem.java.devlogs.controller;

import com.adminsystem.java.common.Result;
import com.adminsystem.java.devlogs.pojo.params.DevLogAddParam;
import com.adminsystem.java.devlogs.pojo.vo.DevLogVO;
import com.adminsystem.java.devlogs.service.DevLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wangpeiao
 */
@RestController
@RequestMapping("/myAdminSystem/devlog")
@RequiredArgsConstructor
public class DevLogController {

    private final DevLogService devLogService;

    /**
     * 查询所有开发日志（无分页）
     *
     * @return 日志列表（VO格式）
     */
    @GetMapping("/list")
    public Result<List<DevLogVO>> getAllDevLogs() {
        List<DevLogVO> logs = devLogService.getAllDevLogs();
        return Result.success(logs);
    }

    /**
     * 新增开发日志
     *
     * @param param 请求参数
     * @return 操作结果
     */
    @PostMapping("/add")
    public Result<Void> addDevLog(@Validated @RequestBody DevLogAddParam param) {
        boolean success = devLogService.addDevLog(param);
        if (success) {
            return Result.success(null);
        } else {
            return Result.fail("新增失败");
        }
    }
}
